package com.ncloud.resman.service.impl;

import com.ncloud.resman.entity.DeviceSwitch;
import com.ncloud.resman.entity.ExportSwitchInfo;
import com.ncloud.resman.mapper.SwitchMapper;
import com.ncloud.resman.service.DeviceSwitchService;
import com.ncloud.resman.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceSwitchServiceImpl implements DeviceSwitchService{
    @Autowired
    private SwitchMapper switchMapper;
    @Autowired
    private SequenceService sequenceService;

    @Override
    public DeviceSwitch getDeviceSwitchByDeviceId(Long deviceId) {

        return switchMapper.getDeviceSwitchByDeviceId(deviceId);
    }

    @Override
    public int insertDeviceSwitch(DeviceSwitch deviceSwitch) {
        if(deviceSwitch.getDeviceId() == null){
            Long id = sequenceService.getSequence("device_id_seq");
            deviceSwitch.setDeviceId(id);
        }
        deviceSwitch.setCreateDate(new Date());
        return switchMapper.insertSwitch(deviceSwitch);
    }

    @Override
    public int updateDeviceSwitch(DeviceSwitch deviceSwitch) {
        deviceSwitch.setUpdateDate(new Date());
        return switchMapper.updateSwitch(deviceSwitch);
    }

    @Override
    public int updateSwitchBase(DeviceSwitch deviceSwitch) {
        return switchMapper.updateSwitchBase(deviceSwitch);
    }

    @Override
    public int updateSwitchManage(DeviceSwitch deviceSwitch) {
        return switchMapper.updateSwitchManage(deviceSwitch);
    }

    @Override
    public int deleteDeviceSwitch(Long deviceId) {
        return switchMapper.deleteDeviceSwitch(deviceId);
    }
	@Override
	public List<ExportSwitchInfo> exportSwitchInfos(String snNum) {
		return switchMapper.exportSwitchInfos(snNum);
	}
}
